Writing a Class

To write the source code for a class:

  1. In a text editor, create the header file.

  2. To create an action, declare a method that takes a single argument named sender and that returns void or that is coerced to be a action, like this:
    - (IBAction)foo: (id)Sender;
  3. To create an outlet, declare an instance variable that is of type Id or has the IBOutlet keyword prefixed to its declaration.

If you're creating the header file in Project Builder, choose File > New in Project. Project Builder automatically creates a header file template for you. You need to add just the actions, outlets, and other member functions and variables.

Here's a sample header file:

#import <AppKit/AppKit.h>@interface TAController:NSObject
{IBOutlet NSTableView *tableView;     /* an outlet */id 
commentsLabel;                        /* another outlet */
    // ...NSMutableDictionary *countryDict;    /* not an outlet */
    // ...
}

/* target/action */
- (void)addRecord:(NSButton *)sender;    /* an action */
- (void)convertCelsius:(id)sender;       /* another action */

/* Data read and write methods */
- (void)populateFields:(Country *)aRec;  /* not an action */
@end
Next Step
Adding a Class
Main Topic
Importing a Class

© 1999 Apple Computer, Inc.